
Ext.define('Roy.controller.base.Controller', {
	extend: 'Ext.app.Controller',
	
	init: function() {
		this.children = new Ext.util.MixedCollection();
		this.actived = undefined;
	},
	
	active : function() {
		if(this.parent) {
			this.parent.activeController(this);
			this.parent.changeActive();
		}
	},

	changeActive : function() {
		if(this.parent) {
			this.parent.actived = this;
			this.parent.changeActive();
		}
	},

	changeDeactive : function() {
		if(this.parent) {
			this.parent.actived = null;
			this.parent.changeDeactive();
		}
	},

	activeTabController : function(controller){
		
	},
	
	activeController: function(controller) {
		this.active();
		var childView = undefined;
//		if(this.hasController(controller)) {
//			var child = this.getController(controller);
//			childView = child.getEwayView();
//			if(this.actived == child) {
//				if(!this.getEwayView()) {
//					this.activeControllerView(childView);
//				}
//				return ;
//			}
//		}
//		else {
//			var child = Ext.create(controller);
//			this.children.add(controller, child);
//			childView = child.makeEwayView();
//		}
		var child = this.getController(controller);
//		if(this.actived == child) {
//			return ;
//		}
		var childView = child.getEwayView();
		this.activeControllerView(childView);
		this.actived = child;
		child.parent = this;
		if(!this.children.get(controller)) {
			this.children.add(controller, child);
			child.init();
		}
		
	},
	
	activeControllerView : function(childView) {
		if(this.getEwayView() && childView) {
			this.getEwayView().activeEwayView(childView);
		}
		else if(this.parent) {
			this.parent.activeControllerView(childView);
		}
	}
	
//	getController : function(controller) {
//        if(typeof controller == 'object'){
//            return controller;
//        }
//        var result = this.children.get(controller);
//        if(!result) {
//        }
//        return result;
//	},
//
//	hasController: function(controller) {
//		var result = this.children.get(controller);
//		if(result) {
//			return true;
//		}
//		else {
//			return false;
//		}
//	}

});